<style scoped>
  .weui-media-box_appmsg .weui-media-box__hd {
    font-size: 12px;
    width: 50px;
    height: 50px;
    line-height: 50px;
    border-radius: 50%;
    background: #ccc;
    color: #fff;
  }
  .weui-media-box_appmsg .weui-media-box__hd.blue {
    background: #296BCC;
  }
  .weui-media-box__desc {
    font-size: 12px;
  }
  .weui-media-box__title {
    white-space: normal;
    font-size: 14px;
    margin-bottom: 5px;
    color: #666;
  }
  .weui-form-preview__bd {
    text-align: left;
  }

  .weui-form-preview {
    position: relative;
    background-color: #fff;
    margin: 1%;
    border-radius: 5px;
  }
  .datalist {
    background: #e3e3e3;
    height: 100%;
    overflow: hidden;
  }
  .datalist.nodata {
    font-size: 14px;
    padding: 5px;
  }
</style>
<template>
  <div class="comon">
    <div class="rj-wrap">
      待办事务
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>

    <div style="overflow:auto;overflow-x: hidden;" v-show="tasks.length > 0">
      <div class="weui-form-preview" v-for="(item, index) in tasks">
        <div class="weui-form-preview__bd" @click="openOrder(item.backUrl, item.orderCode, item.id)">
          <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
            <div class="weui-media-box__hd blue" style="overflow: hidden;">
              {{item.submitter}}
            </div>
            <div class="weui-media-box__bd" style="position: relative;">
              <h4 class="weui-media-box__title" :class="{grey3 : item.status == 1 }">{{item.noticeContent}}</h4>
              <p class="weui-media-box__desc">{{item.createTime}}
              </p>
            </div>
          </a>
        </div>
      </div>
      <div class="weui-loadmore weui-loadmore_line">
        <span class="weui-loadmore__tips">没有更多了</span>
      </div>
    </div>
    <div class="weui-loadmore" v-if="loading">
      <i class="weui-loading"></i>
      <span class="weui-loadmore__tips">正在加载</span>
    </div>
    <div v-show="!loading && tasks.length <= 0" class="datalist nodata">没有待处理任务哦~</div>

  </div>

</template>

<script>

  export default {
    name: 'TaskList',
    data () {
      return {
        nodes: [],
        orderid: '',
        srguid: '',
        departid: '',
        sellformpid: '',
        sellformpcode: '',
        tasks1: [],
        tasks2: [],
        loading: true
      }
    },
    created() {    },
    mounted() {
      this.orderid = this.$route.query.orderid;
      this.srguid = this.$route.query.srguid;
      this.departid = this.$route.query.departid;
      this.sellformpid = this.$route.query.sellformpid;
      this.sellformpcode = this.$route.query.sellformpcode;

      this.getTask();
      this.getTask2();
    },
    computed: {
      tasks: function() {
        return this.tasks2.concat(this.tasks1.map(item => {
          return {
            noticeTitle: item.ordertypename,
            noticeContent: item.noticecontent,
            orderCode: item.ordercode,
            submitter: item.submitter,
            createTime: item.createtime,
            url: item.url,
            operation: item.noticetitle,
            createBy: item.submitterid,
            id: item.guid,
            backUrl: item.backurl,
            status: item.status
          }
        }))
      }
    },
    methods: {
      getTask: function () {
        this.axios({
          method: 'get',
          url: '/sales/Noticeinfo!getPendingNotice.action',
          params: {}
        }).then(response => {
          this.loading = false;

          let data = response.data;
          if(data.status == 'true'){
            this.tasks1 = data.result;
          }else if(data.status=='false'){
            this.toastText(data.result);
          }else{
            this.toastText("获取待审批数据失败!");
          }
        });
      },
      getTask2: function () {
        this.axios({
          method: 'get',
          url: '/prod-api/noticeinfo/noticeinfo/toDoList',
          params: {}
        }).then(response => {
          this.loading = false;
          let data = response.data;
          if(data.code == 200){
            this.tasks2 = data.rows;
          }else if(data.msg){
            this.toastText(data.msg);
          }else{
            this.toastText("获取待审批数据失败!");
          }
        });
      },
      openOrder: function(backurl, ordercode, orderguid) {
        this.axios({
          method: 'post',
          url: '/sales/Noticeinfo!readNotice.action',
          params: {guid: orderguid}
        }).then(response => {
          //成功与否不设置提示
        });
        location.href = backurl.indexOf('?') > -1 ? backurl + '&search=' + ordercode : backurl + '?search=' + ordercode;
      }
    }
  }
</script>
